package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.SystemDictionaryItem;
import cn.wolfcode.crm.mapper.SystemdictionaryitemMapper;
import cn.wolfcode.crm.qo.SystemDictionaryItemQuery;
import cn.wolfcode.crm.service.ISystemDictionaryItemService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SystemDictionaryItemServiceimpl implements ISystemDictionaryItemService {

    @Autowired
    private SystemdictionaryitemMapper systemDictionaryItemMapper;

    @Override
    public void save(SystemDictionaryItem systemDictionaryItem) {
        if(systemDictionaryItem.getSequence()==null){
            int maxSequence = systemDictionaryItemMapper.selectSequenceByParenId(systemDictionaryItem.getParentId());
            systemDictionaryItem.setSequence(maxSequence+1);
        }
        systemDictionaryItemMapper.insert(systemDictionaryItem);
    }

    @Override
    public void deleteByPrimaryKey(Long id) {

        systemDictionaryItemMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void updateByPrimaryKey(SystemDictionaryItem systemDictionaryItem) {
        systemDictionaryItemMapper.updateByPrimaryKey(systemDictionaryItem);
    }

    @Override
    public SystemDictionaryItem get(Long id) {
        return systemDictionaryItemMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<SystemDictionaryItem> selectAll() {
        return systemDictionaryItemMapper.selectAll();
    }

    @Override
    public PageInfo query(SystemDictionaryItemQuery qo) {

        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize(),"sequence");
        List<SystemDictionaryItem> list = systemDictionaryItemMapper.queryForList(qo);
        return new PageInfo(list);
    }

    @Override
    public List<SystemDictionaryItem> selectByDicSn(String job) {
        List<SystemDictionaryItem> list = systemDictionaryItemMapper.selectByDicSn(job);
        return list;
    }

    @Override
    public List<SystemDictionaryItem> selectBySn(String subject) {
        List<SystemDictionaryItem> list =systemDictionaryItemMapper.selectBySn(subject);
        return list;
    }
}
